<template>
  <div>
    <ul>
      <li v-for="item in state.arr" :key="item.id" @click="handleDelete(item.id)">{{item.name}}</li>
    </ul>
  </div>
</template>

<script>
import { reactive } from 'vue'

export default {
  setup() {
    // !reactive 可以包装对象为响应式的数据
    const state = reactive({
      arr: [
        {
          id: 0,
          name: 'ifer',
        },
        {
          id: 1,
          name: 'elser',
        },
        {
          id: 2,
          name: 'xxx',
        },
      ],
    })

    const handleDelete = (id) => {
      // 根据 id 找索引
      const idx = state.arr.findIndex(item => item.id === id)
      // 根据索引去删除
      state.arr.splice(idx, 1)
    }

    return {
      state,
      handleDelete
    }
  }
}
</script>

<style lang="scss" scoped></style>